<template>
	<view class="my-settle-container">
		<!-- 全选 -->
		<label class="radio">
			<radio color="#c00" :checked="isFullCheck" @click="btnClick(!isFullCheck)" /><text>全选</text>
		</label>
		<!-- 合计 -->
		<view class="amount-box">
			合计:<text class="amount">￥{{checkedTotalPrice}}</text>
		</view>
		<!-- 结算按钮 -->
		<view class="btn-settle" @click="settleClick">
			结算({{checkTotalCount}})
		</view>
	</view>
</template>

<script>
	import {mapGetters,mapMutations,mapState} from 'vuex'
	export default {
		name:"my-settle",
		data() {
			return {
				seconds : 3
			};
		},
		computed:{
			...mapGetters('m_cart',['checkTotalCount','checkedTotalPrice' ,'total']),
			...mapState('m_user',['token']),
			...mapGetters('m_user',['addStr']),
			isFullCheck(){
				return this.checkTotalCount === this.total
			}
		},
		methods:{
			...mapMutations('m_cart',['updateGoodsState']),
			...mapMutations('m_user',['updateRedirectInfo']),
			// 全选按钮
			btnClick(e){
				this.updateGoodsState(e)
			},
			// 结算按钮
			settleClick(e){
				if(!this.checkTotalCount) return uni.$showMsg("请选择结算商品")
				if(!this.addStr) return uni.$showMsg("请选择收货地址")
				if(!this.token) return this.delayNavigation()
			},
			// 延时导航的页面
			delayNavigation(){
				this.showTips(this.seconds)
				const timer = setInterval(()=>{
					this.seconds--
					if(this.seconds < 0){
						clearInterval(timer)
						uni.switchTab({
							url:'/pages/my/my',
							success:()=>{
								this.updateRedirectInfo({
									opentype: "swithTab" ,
									from : "/pages/cart/cart"
								})
							}
						})
						this.seconds = 3
						return
					}
					this.showTips(this.seconds)
				},1000)
			},
			showTips(seconds){
				uni.showToast({
					icon:	'none',
					title:	"请登录后再结算！"+seconds+"s之后自动跳转到登录页",
					mask:	true, // 防止点击穿透
					duration: 1500
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
.my-settle-container{
	position: fixed;
	bottom: 0;
	left: 0;
	height: 50px;
	display: flex;
	justify-content: space-between;
	width: 100%;
	align-items: center;
	font-size: 14px;
	background-color: white;
	.radio{
		padding-left: 5px ;
		display: flex;
		align-items: center;
	}
	.amount-box{
		.amount{
			color: #c00;
			font-weight: bold;
		}
	}
	.btn-settle{
		padding: 0 10px;
		background-color: #c00;
		color: white;
		height: 50px;
		line-height: 50px;
		min-width: 100px;
		text-align: center;
	}
}
</style>